package com.example.whatsnext;
import java.util.ArrayList;
import java.util.HashMap;

import com.example.whatsnext.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class ChatAdapter extends BaseAdapter 
{

	
	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater = null;
	//public ImageLoader imageLoader;
	
	public ChatAdapter(Activity a, ArrayList<HashMap<String, String>> d)
	{
		activity = a;
        data = d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //imageLoader = new ImageLoader(activity.getApplicationContext());
	}
	
	
	public int getCount() 
	{
		return data.size();
	}

	public Object getItem(int position) 
	{
		return position;
	}

	public long getItemId(int position) 
	{
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) 
	{
		View vi = convertView;
		if (convertView == null)
		{
			vi = inflater.inflate(R.layout.grid_item, null);
		}
		
		TextView chatName = (TextView)vi.findViewById(R.id.name);
		TextView lastMessage = (TextView)vi.findViewById(R.id.lastMessage);
		TextView countMissedMessages = (TextView)vi.findViewById(R.id.missedMessages);
		//ImageView thumb_image = (ImageView)vi.findViewById(R.id.thumbnail);
		
		HashMap<String, String> chats = new HashMap<String, String>();
		chats = data.get(position);
		
		// Setting all values in ListView
		chatName.setText(chats.get(HomeActivity.KEY_NAME));
		lastMessage.setText(chats.get(HomeActivity.KEY_LASTMESSAGE));
		countMissedMessages.setText(chats.get(HomeActivity.KEY_COUNT_MISSED_MESSAGES));
		return vi;
	}
}
